import { defineStore } from "pinia";
import { Api } from "/@/api";
import { storage } from "../middleware";
export const mainStore = defineStore("main", {
  state: () => {
    return {
      navList: <any>[{ name: "账户管理", path: "/user" }],
      menu: [],
    };
  },
  getters: {},
  actions: {
    changeNav(val: any) {
      this.navList.push(val);
    },
    addMenu() {
      Api.user.loadMenu()?.then((res) => {
        this.menu = res.data;
        storage?.set("menu", JSON.stringify(res.data));
        this.navList = [];
      });
    },
    getMenu() {
      this.menu = JSON.parse(storage?.get("menu") as any);
    },
    deleteNav(val: any) {
      const index = this.navList.findIndex((vals: any) => {
        return vals.path === val;
      });
      this.navList.splice(index, 1);
    },
  },
});
